#[cfg(test)] 
mod test {
    #[tokio::test(flavor="multi_thread")]
    async fn cur_dir() -> tokio::io::Result<()> {
        use tokio::fs;
        let mut entries = fs::read_dir(".").await?;
        while let Some(entry) = entries.next_entry().await? {
            println!("{:?}", entry.path());
        }
        Ok(())
    }

    use tokio::fs::File;
    use tokio::io::AsyncReadExt;
    #[tokio::test(flavor="multi_thread")]
    async fn read_file() -> tokio::io::Result<()> {
        let mut f = File::open("./Cargo.toml").await?;
        let mut buffer = [0; 10];

        let n = f.read(&mut buffer[..]).await?;

        println!("The bytes: {:?}", &buffer[..n]);
        Ok(())
    }
    #[tokio::test(flavor="multi_thread")]
    async fn read_to_end() -> tokio::io::Result<()> {
        let mut f = File::open("./Cargo.toml").await?;
        let mut buffer = Vec::new();

        f.read_to_end(&mut buffer).await?;
        println!("{}", std::str::from_utf8(buffer.as_slice()).unwrap());
        Ok(())
    }


    use tokio::io::AsyncWriteExt;
    #[tokio::test(flavor="multi_thread")]
    async fn write() -> tokio::io::Result<()> {
        
        if tokio::fs::try_exists("foo.txt").await? {
            tokio::fs::remove_file("foo.txt").await?;
        }
        let mut file = tokio::fs::File::create("foo.txt").await?;

        let n = file.write(b"hello world").await?;

        println!("write {n} bytes");

        Ok(())
    }
    #[tokio::test(flavor="multi_thread")]
    async fn write_all() -> tokio::io::Result<()> {
        
        if tokio::fs::try_exists("foo1.txt").await? {
            tokio::fs::remove_file("foo1.txt").await?;
        }
        let mut file = tokio::fs::File::create("foo1.txt").await?;

        file.write_all(b"hello world").await?;

        Ok(())
    }


    #[tokio::test(flavor="multi_thread")]
    async fn io_copy() -> tokio::io::Result<()> {
        if tokio::fs::try_exists("foo1.txt").await? {
            tokio::fs::remove_file("foo1.txt").await?;
        }

        let mut reader: &[u8] = b"hello";
        let mut file = tokio::fs::File::create("foo3.txt").await?;
        
        tokio::io::copy(&mut reader, &mut file).await?;
        Ok(())
    }

}

